package com.moxiao.yfjh.module.blind.controller.admin.constellationspeech;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.common.pojo.CommonResult;
import static com.moxiao.yfjh.framework.common.pojo.CommonResult.success;

import com.moxiao.yfjh.framework.excel.core.util.ExcelUtils;

import com.moxiao.yfjh.framework.operatelog.core.annotations.OperateLog;
import static com.moxiao.yfjh.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.moxiao.yfjh.module.blind.controller.admin.constellationspeech.vo.*;
import com.moxiao.yfjh.module.blind.dal.dataobject.constellationspeech.ConstellationSpeechDO;
import com.moxiao.yfjh.module.blind.convert.constellationspeech.ConstellationSpeechConvert;
import com.moxiao.yfjh.module.blind.service.constellationspeech.ConstellationSpeechService;

@Tag(name = "管理后台 - 相亲会员录音回复")
@RestController
@RequestMapping("/blind/constellation-speech")
@Validated
public class ConstellationSpeechController {

    @Resource
    private ConstellationSpeechService constellationSpeechService;

    @PostMapping("/create")
    @Operation(summary = "创建相亲会员录音回复")
    @PreAuthorize("@ss.hasPermission('blind:constellation-speech:create')")
    public CommonResult<Long> createConstellationSpeech(@Valid @RequestBody ConstellationSpeechCreateReqVO createReqVO) {
        return success(constellationSpeechService.createConstellationSpeech(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新相亲会员录音回复")
    @PreAuthorize("@ss.hasPermission('blind:constellation-speech:update')")
    public CommonResult<Boolean> updateConstellationSpeech(@Valid @RequestBody ConstellationSpeechUpdateReqVO updateReqVO) {
        constellationSpeechService.updateConstellationSpeech(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除相亲会员录音回复")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('blind:constellation-speech:delete')")
    public CommonResult<Boolean> deleteConstellationSpeech(@RequestParam("id") Long id) {
        constellationSpeechService.deleteConstellationSpeech(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得相亲会员录音回复")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('blind:constellation-speech:query')")
    public CommonResult<ConstellationSpeechRespVO> getConstellationSpeech(@RequestParam("id") Long id) {
        ConstellationSpeechDO constellationSpeech = constellationSpeechService.getConstellationSpeech(id);
        return success(ConstellationSpeechConvert.INSTANCE.convert(constellationSpeech));
    }

    @GetMapping("/list")
    @Operation(summary = "获得相亲会员录音回复列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('blind:constellation-speech:query')")
    public CommonResult<List<ConstellationSpeechRespVO>> getConstellationSpeechList(@RequestParam("ids") Collection<Long> ids) {
        List<ConstellationSpeechDO> list = constellationSpeechService.getConstellationSpeechList(ids);
        return success(ConstellationSpeechConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得相亲会员录音回复分页")
    @PreAuthorize("@ss.hasPermission('blind:constellation-speech:query')")
    public CommonResult<PageResult<ConstellationSpeechRespVO>> getConstellationSpeechPage(@Valid ConstellationSpeechPageReqVO pageVO) {
        PageResult<ConstellationSpeechDO> pageResult = constellationSpeechService.getConstellationSpeechPage(pageVO);
        return success(ConstellationSpeechConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出相亲会员录音回复 Excel")
    @PreAuthorize("@ss.hasPermission('blind:constellation-speech:export')")
    @OperateLog(type = EXPORT)
    public void exportConstellationSpeechExcel(@Valid ConstellationSpeechExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ConstellationSpeechDO> list = constellationSpeechService.getConstellationSpeechList(exportReqVO);
        // 导出 Excel
        List<ConstellationSpeechExcelVO> datas = ConstellationSpeechConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "相亲会员录音回复.xls", "数据", ConstellationSpeechExcelVO.class, datas);
    }

}
